<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form id="addToOrder" method="post">
	<input type="hidden" name="balanceCount" id="balanceCount"/>
    <input type="hidden" name="goodsId" id="goodsId"/>
    <table align="center" cellspacing="10">
        <tr>
            <td>
                <label for="soBillId">订单号:</label>
                <input id="soBillId" class="easyui-combobox" name="soBillId" style="width: 60%"
                       data-options="valueField:'id',textField:'ref',method:'post',url:'api/bill/so/findAllSoBill'" />
            </td>
            <td>
                <label for="wsBillId">出库单:</label>
                <input id="wsBillId" class="easyui-combobox" name="wsBillId" style="width: 60%" data-options="valueField:'id',textField:'ref',method:'get',url:'api/bill/ws/findWsBill'"/>
            </td>
        </tr>
        <tr>
            <td>
                <label>数量：</label>
                <input class="easyui-numberspinner" id="goodsCount" name="goodsCount" style="width:80px;" value="1"  data-options="
				onChange: function(value){
                var goodsPrice=$('#goodsPrice').val();
                var goodsMoney=value*goodsPrice;
                $('#goodsMoney').textbox('setValue',goodsMoney);
                $('#moneyWithTax').textbox('setValue',goodsMoney);
				}
			"/>
            </td>
            <td>
                <label for="goodsPrice">单价：</label>
                <input class="easyui-textbox" name="goodsPrice" id="goodsPrice"   readonly="true"/>
            </td>
        </tr>
        <tr>
           <td>
               <label for="goodsMoney">金额：</label>
               <input class="easyui-textbox" name="goodsMoney" id="goodsMoney"/>
           </td>
            <td>
                <label for="taxRate">税率(%)：</label>
                <em><input name="taxRate" id="taxRate" value="0.0" /></em>
            </td>
        </tr>
        <tr>
            <td>
                <label for="tax">税金：</label>
                <input class="easyui-textbox" name="tax" id="tax" value="0.0"/>
            </td>
            <td>
                <label for="moneyWithTax">价税合计：</label>
                <input class="easyui-textbox" name="moneyWithTax" id="moneyWithTax"/>
            </td>

        </tr>
        <tr>
            <td colspan="2" align="center">
                <a  data-options="iconCls:'icon-ok'"  class="easyui-linkbutton" onclick="addToOrderForm()" >加入订单</a>
                <a  data-options="iconCls:'icon-ok'"  class="easyui-linkbutton" onclick="addToWsBillForm()" style="margin-left: 60px;" >直接出库</a>
                <a  data-options="iconCls:'icon-no'"  class="easyui-linkbutton" onclick="closeToOrderForm()" style="margin-left: 60px;">取消</a>
            </td>
        </tr>
    </table>
</form>


<script>
    $(function () {
        var goods=$("#goods").val();
        var jsonData=(JSON.parse(goods)) ;
        $('#goodsPrice').val(jsonData.salePrice);
        $('#goodsMoney').val(jsonData.salePrice);
        $('#goodsId').val(jsonData.id);
        $('#balanceCount').val(jsonData.balanceCount);
        $('#moneyWithTax').val(jsonData.salePrice);
    });
    $('#taxRate').blur(function () {
        var goodsMoney=$('#goodsMoney').val();
        var taxRate=$('#taxRate').val();
        var tax=goodsMoney*(taxRate/100);
        $('#tax').textbox('setValue',tax);
        var moneyWithTax=parseFloat(goodsMoney)+parseFloat(tax);
        $('#moneyWithTax').textbox('setValue',moneyWithTax);
    });
   function addToOrderForm() {
       $('#addToOrder').form('submit',{
           url:'api/bill/so/detail',
           onSubmit: function () {
               return $(this).form('enableValidation').form('validate');
           }, success: function (data) {
               data = eval('(' + data + ')');
                if(data.data=1){
                    $.messager.show({
                        title: '温馨提示',
                        msg: data.message,
                        timeout: 3000,
                        showType:'show',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    $('#addToOrderDialog').dialog('close');
                    $('#goodsGrid').datagrid('reload');
                }else{
                    $.messager.alert('失败提示', data.message, 'warning');
                }
           }
       })
   }
</script>
